package photorganizer.common.helper;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import photorganizer.common.exception.TechnicalException;


public class ReflectHelper {

	public static Method getDeclaredMethod(Class<?> clazz, String name, Class<?>[] parameterTypes) {
		try {
			return clazz.getDeclaredMethod(name, parameterTypes);
		}
		catch (NoSuchMethodException e) {
			throw new TechnicalException("Failed to get method: " + name + " on class: " + clazz.getName(), e);
		}
	}

	public static Object invoke(Method method, Object object, Object... parameters) throws Throwable {
		try {
			return method.invoke(object, parameters);
		}
		catch (IllegalAccessException e) {
			throw new TechnicalException("Failed to invoke method: " + method, e);
		}
		catch (InvocationTargetException e) {
			throw e.getTargetException();
		}
	}

	private ReflectHelper() {
		assert false;
	}

}
